/**
 * @ClassName LC53
 * @Author ykx
 * @Date 2024/3/19 12:20
 * @Version 1.0
 */
public class LC53 {
    public int maxSubArray(int[] nums) {
        int result = nums[0];
        int sum = 0;
        for (int num : nums) {
            if (sum >= 0) {
                sum += num;
            } else {
                sum = num;
            }
            result = Math.max(sum, result);
        }
        return result;
    }
}
